<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>通过名称获取特定的外部变量，并且可以通过过滤器处理它</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.filter-input-array.html">« filter_input_array</a></li>
      <li style="float: right;"><a href="function.filter-list.html">filter_list »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.filter.html">过滤器函数</a></li>
    <li>通过名称获取特定的外部变量，并且可以通过过滤器处理它</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.filter-input" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">filter_input</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.2.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">filter_input</span> &mdash; <span class="dc-title">通过名称获取特定的外部变量，并且可以通过过滤器处理它</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.filter-input-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>filter_input</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$type</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$var_name</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$filter</code><span class="initializer"> = <strong><code>FILTER_DEFAULT</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type">array</span>|<span class="type">int</span></span> <code class="parameter">$options</code><span class="initializer"> = 0</span></span><br>): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>


 </div>

 <div class="refsect1 parameters" id="refsect1-function.filter-input-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">type</code></dt>

     <dd>

      <p class="para">
       <strong><code>INPUT_GET</code></strong>, <strong><code>INPUT_POST</code></strong>,
       <strong><code>INPUT_COOKIE</code></strong>, <strong><code>INPUT_SERVER</code></strong>或
       <strong><code>INPUT_ENV</code></strong>之一。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">var_name</code></dt>

     <dd>

      <p class="para">
       待获取的变量名。
      </p>
     </dd>

    
    
 
  <dt>
<code class="parameter">filter</code></dt>

  <dd>

   <p class="para">
    The ID of the filter to apply. The <a href="filter.filters.html" class="xref">Types of filters</a>
    manual page lists the available filters.
   </p>
   <p class="para">
    If omitted, <strong><code>FILTER_DEFAULT</code></strong> will be used, which is
    equivalent to
    <a href="filter.filters.sanitize.html" class="link"><strong><code>FILTER_UNSAFE_RAW</code></strong></a>.
    This will result in no filtering taking place by default.
   </p>
  </dd>

 

    
     <dt>
<code class="parameter">options</code></dt>

     <dd>

      <p class="para">
       一个选项的关联数组，或者按位区分的标示。如果过滤器接受选项，可以通过数组的 &quot;flags&quot; 位去提供这些标示。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.filter-input-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   如果成功的话返回所请求的变量。如果过滤失败则返回 <strong><code>false</code></strong>，如果<code class="parameter">var_name</code> 不存在的话则返回
   <strong><code>null</code></strong>。如果标示 <strong><code>FILTER_NULL_ON_FAILURE</code></strong> 被使用了，那么当变量不存在时返回 <strong><code>false</code></strong>，当过滤失败时返回 <strong><code>null</code></strong>。
   </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.filter-input-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5065">
    <p><strong>示例 #1 一个 <span class="function"><strong>filter_input()</strong></span> 的例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$search_html&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">filter_input</span><span style="color: #007700">(</span><span style="color: #0000BB">INPUT_GET</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'search'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">FILTER_SANITIZE_SPECIAL_CHARS</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$search_url&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">filter_input</span><span style="color: #007700">(</span><span style="color: #0000BB">INPUT_GET</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'search'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">FILTER_SANITIZE_ENCODED</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"You&nbsp;have&nbsp;searched&nbsp;for&nbsp;</span><span style="color: #0000BB">$search_html</span><span style="color: #DD0000">.\n"</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #DD0000">"&lt;a&nbsp;href='?search=</span><span style="color: #0000BB">$search_url</span><span style="color: #DD0000">'&gt;Search&nbsp;again.&lt;/a&gt;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
You have searched for Me &amp;#38; son.
&lt;a href=&#039;?search=Me%20%26%20son&#039;&gt;Search again.&lt;/a&gt;
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.filter-input-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.filter-var.html" class="function" rel="rdfs-seeAlso">filter_var()</a> - 使用特定的过滤器过滤一个变量</span></li>
    <li class="member"><span class="function"><a href="function.filter-input-array.html" class="function" rel="rdfs-seeAlso">filter_input_array()</a> - 获取一系列外部变量，并且可以通过过滤器处理它们</span></li>
    <li class="member"><span class="function"><a href="function.filter-var-array.html" class="function" rel="rdfs-seeAlso">filter_var_array()</a> - 获取多个变量并且过滤它们</span></li>
    <li class="member"><a href="filter.filters.html" class="xref">Types of filters</a></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>